package me.haoliang

/**
  * author: planck 
  * createTime: 2016/10/18.
  */
object MatchScala {

  val map = Map("a" -> "a", "b" -> "b")

  def main(args: Array[String]): Unit = {
    matchTest4
  }

  def matchTest(x: Any): String = x match {
    case 1 => "int one" //匹配x为数字1
    case "1" => "char one" //匹配x为字符1
    case _: Int => "x is int" //匹配x是一个int类型
    case _ => "any" //匹配x是任何值
  }


  def matchTestIf(x: Any): String = x match {
    case y: Int if (y < 10) => "int less than 10"
    case y: Int if (y >= 10) => "int more than or equal to 10"
    case _ => "any"
  }

  def matchTest2(a: Option[String], c: Option[String]) = {
    (a, c) match { //case class匹配
      case (Some(a), Some(c)) =>
        println("1")
      case (Some(a), None) =>
        println("2")
      case (_, _) =>
        println("3")
    }
  }

  def matchTest3 = {
    List(1, 2) match {
      case List(x, 2) => println(x)
    }
  }


  def matchTest4 = {
    (1, (1, 2)) match {
      case (_, _@(1, _)) => println("ok")
    }
  }

}
